from django.conf.urls import patterns, include, url
from cvirt import settings
from django.shortcuts import HttpResponseRedirect
from cvirt.manager.views import ExpiringObtainAuthToken
from cvirt.manager.view.login import LogoutView


urlpatterns = patterns('',
    url(r'^static/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.STATICFILES_DIRS[0]}),
    url(r'^web/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.STATICFILES_DIRS[0]}),
)

if settings.DEBUG:
    from django.contrib import admin
    admin.autodiscover()
    urlpatterns += patterns('',
        url(r'^admin/', include(admin.site.urls))
    )

urlpatterns += patterns('cvirt.manager',
    url(r'^api/',include('cvirt.manager.urls')),  #this url define must be top
    url(r'^$', lambda x: HttpResponseRedirect('/web/index.html')),
)

urlpatterns += patterns('',
    url(r'^api-token-auth', ExpiringObtainAuthToken.as_view()),
    url(r'^logout', LogoutView.as_view())
)